<?php
/**
 * Cube PHP Framework
 * 
 * The contents of this file are subject to the Mozilla Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License at
 * http://www.mozilla.org/MPL/
 * 
 * @author Dillen / Steffen
 */

namespace Library\Mvc;

/** 
 * Controller base class
 * 
 * 	$var = new Test('test');
 * 	$var->run();
 * 	
 * 	$downloads = $var->getDownloadQeue();
 * 
 * # Usage:
 * 
 * 	echo "Hoi";
 * 
 * 
 * @class Library.Mvc.Controller
 * @extends Library.Web.WebApplication
 * @abstract
 */
class Controller extends \Library\Web\WebApplication
{
    private $_config;
    
	/**
	 * Layout
	 * 
	 * @property {Library.Mvc.Layout} layout
	 * @var \Library\Mvc\Layout
	 */
	public $layout;
	
	/**
	 * View
	 * 
	 * @property {Library.Mvc.View} view
	 * @var \Library\Mvc\View
	 */
	public $view;
	
	/**
	 * Router instance
	 * 
	 * @property {Library.Mvc.Router} router
	 * @var \Library\Mvc\Router
	 */
	public $router;
	
	/**
	 * Request instance
	 * 
	 * @property {Library.Mvc.Request} request
	 * @var \Library\Mvc\Request
	 */
	public $request;
	
	/**
	 * Abstract controller init
	 * 
	 * We do not use the constructor, because we need to inject several objects.
	 * 
	 * @method __construct
	 * @private
	 */
	final public function __construct()
	{
        $this->_config = \Library\Platform::getConfig();
        
		parent::__construct();
	}
    
    public function createResponse()
    {
        $this->layout = new Layout($this->request);
        
        return $this->layout;
    }
    
    public function parseResponse()
    {
		if ($this->_config['layout']['auto_render'])
		{
			$this->layout->renderLayout();
		}
    }
	
	/**
	 * Initial method for constructor used by user
	 * 
	 * @method __init
	 */
	public function __init()
	{
		
	}
}
